package cn.edu.stu.mapper;

import cn.edu.stu.bean.MicRecord;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface MicRecordMapper {
    int deleteByPrimaryKey(Integer recordId);

    int insert(MicRecord record);

    MicRecord selectByPrimaryKey(Integer recordId);

    List<MicRecord> selectAll();

    int updateByPrimaryKey(MicRecord record);

    @MapKey("song_id")
    List<Map<String,Object>> selectRecordBuFuzzyName(String name);

    //只模糊查询前半部分的歌名去掉id

    List<Map<String,Object>> selectRecordsWithPartName(@Param("name") String name, @Param("full") String fullName);

    List<Map<String, Object>> selectByUid(long uid);

    List<Map<String, Object>> selectAllRecordWithArtistName();

    List<Map<String, Object>> selectAllRecord();

    @Delete("delete from mic_record where song_id = #{songId} and user_id = #{userId}")
    int deleteByKeyAndUserId(@Param("songId") Integer songId, @Param("userId")Long userId);

    List<Integer> countWithSongIdAndUserId(int songId, Long userId);

    @Select("select count(*) from mic_record where song_id = #{songId}")
    int countBySongId(Integer songId);

    @Select("select * from mic_record where song_id = #{songId} and user_id = #{userId}")
    List<MicRecord> selectByUidAndSongId(@Param("songId") Integer songId, @Param("userId")Long userId);

    @Delete("delete from mic_record where song_id = #{songId}")
    int deleteBySongId(Integer songId);

    @Delete("delete from mic_record where song_id = #{userId")
    int deleteByUserId(long userId);
}